STYLE: Replace declare-then-Fill(N) with ::Filled(N) factory method#6010
Conversation
|
| Filename | Overview |
|---|---|
| Modules/Core/ImageFunction/include/itkGaussianInterpolateImageFunction.hxx | Replaces three Fill(0.0) calls with {} value-initialization on FixedArray accumulators — semantically equivalent since FixedArray's defaulted constructor value-initializes its C-array to zero |
| Modules/Registration/Common/include/itkLandmarkBasedTransformInitializer.hxx | Replaces Fill(0.0) with {} on VectorType accumulators at three sites — correct zero-initialization |
| Modules/Filtering/Path/include/itkFourierSeriesPath.hxx | Replaces output.Fill(0) with output{} in Evaluate and EvaluateDerivative — correct zero-initialization of path outputs |
| Modules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxx | Replaces Fill(0.0) with {} on cosCoefficient/sinCoefficient VectorType accumulators inside the harmonic loop |
| Modules/Filtering/QuadEdgeMeshFiltering/include/itkSmoothingQuadEdgeMeshFilter.hxx | Replaces Fill(0) with {} on VectorType accumulator in GenerateData |
| Modules/Segmentation/KLMRegionGrowing/include/itkKLMRegionGrowImageFilter.hxx | Replaces Fill(0) with {} on index accumulators inside InitializeKLM loop — correct zero-initialization |
| Modules/Video/Core/include/itkVideoStream.h | Replaces start.Fill(0) with start{} in header example code |
| Modules/Core/Common/test/itkBSplineInterpolationWeightFunctionTest.cxx | Replaces ContinuousIndexType declare+Fill(4.15) with itk::MakeFilled |
| Modules/Filtering/ImageGrid/test/itkBSplineControlPointImageFunctionTest.cxx | Mixed: size/spacing use MakeFilled, index/origin use {}; subsequent .Fill() calls on the same mutable auto variables at lines 53-65 remain valid |
| Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest3.cxx | Consolidates size declaration to itk::MakeFilled with the computed value inline |
| Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx | Replaces multiple declare+Fill patterns for domain/velocity field parameters with MakeFilled and {} initialization |
| Modules/Registration/Common/test/itkMultiResolutionPyramidImageFilterTest.cxx | Replaces Vector declare+Fill with itk::MakeFilled using the computed shift value inline |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["T var (uninitialized)"] --> B["var.Fill(N) — explicit init"]
C["auto var = itk::MakeFilled<T>(N)"] --> D["var initialized to N at construction"]
E["T var{}"] --> F["var zero-initialized at construction"]
A -. "replaced by (non-zero N)" .-> C
A -. "replaced by (zero N)" .-> E
B -. removed .-> C
B -. removed .-> E
style A fill:#f9f,stroke:#333
style B fill:#f9f,stroke:#333
style C fill:#9f9,stroke:#333
style D fill:#9f9,stroke:#333
style E fill:#9f9,stroke:#333
style F fill:#9f9,stroke:#333
Reviews (2): Last reviewed commit: "STYLE: Use {}-initialization for zero-fi..." | Re-trigger Greptile
Modules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxx
Outdated
Show resolved
Hide resolved
dzenanz
left a comment
There was a problem hiding this comment.
Possibly squash commits. Good even as-is.
Using find_declare_then_init.py --pattern fill_nonzero, replaced the two-line pattern: Type var; var.Fill(N); with the single-line form: auto var = itk::MakeFilled<Type>(N); // test files auto var = MakeFilled<Type>(N); // .hxx (already in itk::) across 44 files in Modules/ (excluding Remote/, BridgeOpenCV, BridgeVXL, and itkVectorMeanImageFunction.hxx which uses VariableLengthVector). Follow-up to commit 6cb6bf9 by N-Dekker "STYLE: Replace `T var; var.Fill(x)` with `auto var = MakeFilled<T>(x)`" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Using find_declare_then_init.py --pattern fill_zero, replaced the
two-line pattern:
Type var;
var.Fill(0);
with the single-line value-initialization:
Type var{};
{}-initialization zero-initializes all elements for FixedArray and its
subclasses (IndexType, SizeType, SpacingType, PointType, VectorType,
etc.), which is the canonical C++ idiom for zero-initialization and
preserves the correct derived type (unlike ::Filled(0) which returns
the base class).
Applies to 25 files in Modules/ (excluding Remote/, BridgeOpenCV,
BridgeVXL).
Follow-up to commit 427df79 by hjmjohnson
"STYLE: Use {}-initialization for zero-filled FixedArray-derived types"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks @dzenanz I am doing a more complete review and making a more extensive addresing of this style of fix. I'm moving it to a draft until I determine if the a more complete solution can be found. |
427df79 to
787267e
Compare
ARMBUILD-Python failure analysisThe Root cause: Evidence:
Likely cause: Transient OOM on the ARM64 runner due to concurrent memory pressure. A re-run should resolve it. |
d1b4174
into
InsightSoftwareConsortium:main
Summary
Replaces the verbose two-line FixedArray initialization pattern with the modern single-line static factory method
::Filled(v).Before:
ImageType::SizeType size; size.Fill(16);After:
Rules applied
constexpr autoused when the variable is never subsequently modified (test files with concrete types)auto(withoutconstexpr) used for accumulator variables in loop bodies (.hxxtemplate implementations)Fill()is immediately followed by element-wise overrides (size[0] = w), or wheretypenamedisambiguation in deeply nested template parameter scopes makes the replacement non-trivialFiles changed
Modules/IO/NRRD/test/itkNrrdLocaleTest.cxxSizeType+IndexType→constexpr autoModules/Video/BridgeOpenCV/test/itkOpenCVVideoIOTest.cxxPointType→constexpr autoModules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxxVectorTypeaccumulators →autoModules/Filtering/QuadEdgeMeshFiltering/include/itkSmoothingQuadEdgeMeshFilter.hxxVectorTypeaccumulator →autoPure style change — no semantic changes.
Suggested by @N-Dekker in #6003 (comment)